package com.shr.newcoder;

import java.util.Scanner;

public class NtesGame_2 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in) ;
		int dimension = sc.nextInt() ;
		int calCount = sc.nextInt() ;
		int[][] data = new int[dimension][dimension] ;
		for(int i = 0;i<dimension;i++){
			for(int j = 0;j<dimension;j++){
				data[i][j] = sc.nextInt() ;
			}
		}
//		new ArrayList<>().subList(fromIndex, toIndex)
		int max = Integer.MIN_VALUE ;
		for(int i = 0;i<=dimension-calCount;i++){
			for(int j = 0;j<=dimension-calCount;j++){
				int mValue = calMax(data, i ,j, calCount) ;
				if(mValue > max)
					max = mValue;
			}
		}
		System.out.println(max);
		sc.close();
	}

	private static int calMax(int[][] data, int i, int j, int calCount) {
		int max = Integer.MIN_VALUE ;
		for(int t = i;t<i+calCount;t++){
			int s = 0;
			for(int k = j;k<calCount;k++){
				s += data[t][k] ;
				if(s>max)
					max = s;
			}
		}
		
		for(int k = j;k<j+calCount;k++){
			int s = 0;
			for(int t = i;t<calCount;t++){
				s += data[t][k] ;
				if(s>max)
					max = s;
			}
		}
		
		int s1 = 0;
		int s2 = 0;
		for(int t = 0;t<calCount;t++){
			s1 += data[i+t][j+t];
			s2 += data[i+t][j+calCount-1-t];
		}
		if(Math.max(s1, s2) > max)
			max = Math.max(s1, s2);
		return max;
	}
}
